package com.eunion.core.common.request;

import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;

public class Sorting {

    private String orderBy;

    private String order;

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public Order toOrder() {
        Direction direction;
        if ("asc".equalsIgnoreCase(order)) {
            direction = Direction.ASC;
        } else if ("desc".equalsIgnoreCase(order)) {
            direction = Direction.DESC;
        } else {
            direction = Direction.ASC;
        }
        return new Order(direction, orderBy);
    }

}
